@@ -88,6 +88,7 @@ |
||
88 | 88 |
|
89 | 89 |
<service android:name=".service.UploadService" /> |
90 | 90 |
|
91 |
+ <service android:name=".service.OrderDealService"/> |
|
91 | 92 |
|
92 | 93 |
</application> |
93 | 94 |
|
@@ -0,0 +1,14 @@ |
||
1 |
+package ai.pai.lensman.bean; |
|
2 |
+ |
|
3 |
+/** |
|
4 |
+ * Created by chengzhenyu on 2016/8/27. |
|
5 |
+ */ |
|
6 |
+ |
|
7 |
+public class OrderBean { |
|
8 |
+ public String orderId; |
|
9 |
+ public float orderMoney; |
|
10 |
+ public long orderTime; |
|
11 |
+ public String buyerId; |
|
12 |
+ public String buyerName; |
|
13 |
+ public PhotoBean photoBean; |
|
14 |
+} |
@@ -10,6 +10,7 @@ import com.android.common.utils.LogHelper; |
||
10 | 10 |
import java.util.ArrayList; |
11 | 11 |
|
12 | 12 |
import ai.pai.lensman.App; |
13 |
+import ai.pai.lensman.bean.OrderBean; |
|
13 | 14 |
import ai.pai.lensman.bean.PhotoBean; |
14 | 15 |
import ai.pai.lensman.bean.SessionBean; |
15 | 16 |
|
@@ -250,4 +251,103 @@ public class DBService { |
||
250 | 251 |
return photoBean; |
251 | 252 |
} |
252 | 253 |
|
254 |
+ public void addOrderBean(OrderBean bean){ |
|
255 |
+ SQLiteDatabase db = null; |
|
256 |
+ synchronized (DB_LOCK) { |
|
257 |
+ try { |
|
258 |
+ db = dbHelper.getWritableDatabase(); |
|
259 |
+ db.beginTransaction(); |
|
260 |
+ db.insertWithOnConflict(DBHelper.ORDER_INFO_TABLE, null, orderBean2ContentValues(bean), |
|
261 |
+ SQLiteDatabase.CONFLICT_REPLACE); |
|
262 |
+ db.setTransactionSuccessful(); |
|
263 |
+ } catch (Exception e) { |
|
264 |
+ LogHelper.d(TAG, "dbservice addOrderBean error happen " + e); |
|
265 |
+ } finally { |
|
266 |
+ try { |
|
267 |
+ db.endTransaction(); |
|
268 |
+ } catch (Exception e) { |
|
269 |
+ e.printStackTrace(); |
|
270 |
+ } |
|
271 |
+ closeDB(db); |
|
272 |
+ } |
|
273 |
+ } |
|
274 |
+ } |
|
275 |
+ |
|
276 |
+ public void updateOrderBean(OrderBean bean){ |
|
277 |
+ addOrderBean(bean); |
|
278 |
+ } |
|
279 |
+ |
|
280 |
+ |
|
281 |
+ private OrderBean cursor2OrderBean(Cursor c) { |
|
282 |
+ OrderBean item = new OrderBean(); |
|
283 |
+ item.buyerId = c.getString(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.BUYER_ID)); |
|
284 |
+ item.buyerName= c.getString(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.BUYER_NAME)); |
|
285 |
+ item.orderId = c.getString(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.ORDER_ID)); |
|
286 |
+ item.orderMoney= c.getFloat(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.ORDER_MONEY)); |
|
287 |
+ item.orderTime = c.getLong(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.ORDER_TIME)); |
|
288 |
+ item.photoBean = new PhotoBean(); |
|
289 |
+ item.photoBean.lensmanId = c.getString(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.LENSMAN_ID)); |
|
290 |
+ item.photoBean.sessionId = c.getString(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.SESSION_ID)); |
|
291 |
+ item.photoBean.isRawPhoto =(c.getInt(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.IS_RAW_PHOTO))>0); |
|
292 |
+ item.photoBean.uploadStatus = c.getInt(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.UPLOADED_STATUS)); |
|
293 |
+ item.photoBean.captureTime = c.getLong(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.CAPTURE_TIME)); |
|
294 |
+ item.photoBean.photoId = c.getLong(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.PHOTO_ID)); |
|
295 |
+ item.photoBean.photoName = c.getString(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.PHOTO_NAME)); |
|
296 |
+ item.photoBean.photoPath = c.getString(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.PHOTO_PATH)); |
|
297 |
+ item.photoBean.sessionDate = c.getLong(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.SESSION_DATE)); |
|
298 |
+ item.photoBean.sessionSeq = c.getInt(c.getColumnIndex(DBHelper.ORDER_INFO_COLUMNS.SESSION_SEQ)); |
|
299 |
+ return item; |
|
300 |
+ } |
|
301 |
+ |
|
302 |
+ private ContentValues orderBean2ContentValues(OrderBean orderBean) { |
|
303 |
+ ContentValues cv = new ContentValues(); |
|
304 |
+ cv.put(DBHelper.ORDER_INFO_COLUMNS.BUYER_ID, orderBean.buyerId); |
|
305 |
+ cv.put(DBHelper.ORDER_INFO_COLUMNS.BUYER_NAME,orderBean.buyerName); |
|
306 |
+ cv.put(DBHelper.ORDER_INFO_COLUMNS.ORDER_ID,orderBean.orderId); |
|
307 |
+ cv.put(DBHelper.ORDER_INFO_COLUMNS.ORDER_MONEY,orderBean.orderMoney); |
|
308 |
+ cv.put(DBHelper.ORDER_INFO_COLUMNS.ORDER_TIME,orderBean.orderTime); |
|
309 |
+ PhotoBean item = orderBean.photoBean; |
|
310 |
+ cv.put(DBHelper.ORDER_INFO_COLUMNS.CAPTURE_TIME, item.captureTime); |
|
311 |
+ cv.put(DBHelper.ORDER_INFO_COLUMNS.IS_RAW_PHOTO, item.isRawPhoto ? 1: 0); |
|
312 |
+ cv.put(DBHelper.ORDER_INFO_COLUMNS.PHOTO_ID, item.photoId); |
|
313 |
+ cv.put(DBHelper.ORDER_INFO_COLUMNS.PHOTO_NAME, item.photoName); |
|
314 |
+ cv.put(DBHelper.ORDER_INFO_COLUMNS.PHOTO_PATH, item.photoPath); |
|
315 |
+ cv.put(DBHelper.ORDER_INFO_COLUMNS.SESSION_ID, item.sessionId); |
|
316 |
+ cv.put(DBHelper.ORDER_INFO_COLUMNS.LENSMAN_ID,item.lensmanId); |
|
317 |
+ cv.put(DBHelper.ORDER_INFO_COLUMNS.UPLOADED_STATUS,item.uploadStatus); |
|
318 |
+ cv.put(DBHelper.ORDER_INFO_COLUMNS.SESSION_DATE,item.sessionDate); |
|
319 |
+ cv.put(DBHelper.ORDER_INFO_COLUMNS.SESSION_SEQ,item.sessionSeq); |
|
320 |
+ return cv; |
|
321 |
+ } |
|
322 |
+ |
|
323 |
+ public OrderBean getNextDealOrder(){ |
|
324 |
+ LogHelper.d(TAG, "dbservice getNextDealOrder "); |
|
325 |
+ OrderBean orderBean = null; |
|
326 |
+ SQLiteDatabase db = null; |
|
327 |
+ Cursor c = null; |
|
328 |
+ synchronized (DB_LOCK) { |
|
329 |
+ try { |
|
330 |
+ db = dbHelper.getReadableDatabase(); |
|
331 |
+ db.beginTransaction(); |
|
332 |
+ c = db.rawQuery("select * from " + DBHelper.ORDER_INFO_TABLE + " where " |
|
333 |
+ + DBHelper.ORDER_INFO_COLUMNS.UPLOADED_STATUS + " = '" + 0 + "'"+" order by " |
|
334 |
+ + DBHelper.ORDER_INFO_COLUMNS.ORDER_TIME + " desc limit 1 ", null); |
|
335 |
+ if (c.moveToNext()) { |
|
336 |
+ orderBean = cursor2OrderBean(c); |
|
337 |
+ } |
|
338 |
+ db.setTransactionSuccessful(); |
|
339 |
+ } catch (Exception e) { |
|
340 |
+ LogHelper.d(TAG, "dbservice getNextDealOrder error happen " + e); |
|
341 |
+ } finally { |
|
342 |
+ try { |
|
343 |
+ db.endTransaction(); |
|
344 |
+ } catch (Exception e) { |
|
345 |
+ e.printStackTrace(); |
|
346 |
+ } |
|
347 |
+ closeCursorAndDB(c, db); |
|
348 |
+ } |
|
349 |
+ } |
|
350 |
+ return orderBean; |
|
351 |
+ } |
|
352 |
+ |
|
253 | 353 |
} |
@@ -6,82 +6,57 @@ import android.os.Binder; |
||
6 | 6 |
import android.os.IBinder; |
7 | 7 |
|
8 | 8 |
import com.android.common.executors.ThreadExecutor; |
9 |
-import com.android.common.utils.LogHelper; |
|
10 | 9 |
|
11 |
-import ai.pai.lensman.bean.PhotoBean; |
|
12 |
-import ai.pai.lensman.db.DBService; |
|
10 |
+import java.util.HashMap; |
|
13 | 11 |
|
14 |
-public class OrderDealService extends Service implements UploadTask.OnPhotoUploadListener{ |
|
12 |
+import ai.pai.lensman.bean.OrderBean; |
|
13 |
+import ai.pai.lensman.db.Preferences; |
|
14 |
+import ai.pai.lensman.utils.HttpPostTask; |
|
15 | 15 |
|
16 |
- private PhotoBean currentPhoto; |
|
17 |
- private PhotoUploadListener listener; |
|
16 |
+public class OrderDealService extends Service{ |
|
18 | 17 |
|
19 | 18 |
@Override |
20 | 19 |
public IBinder onBind(Intent intent) { |
21 |
- return new MyBinder(); |
|
20 |
+ return new OrderServiceBinder(); |
|
22 | 21 |
} |
23 | 22 |
|
24 | 23 |
@Override |
25 | 24 |
public int onStartCommand(Intent intent, int flags, int startId) { |
26 |
- if(intent!=null && intent.getSerializableExtra("photo")!=null){ |
|
27 |
- PhotoBean bean = (PhotoBean) intent.getSerializableExtra("photo"); |
|
28 |
- bean.uploadStatus = PhotoBean.UploadStatus.STATUS_NO_BEGIN; |
|
29 |
- DBService.getInstance().updatePhotoBean(bean); |
|
30 |
- } |
|
31 |
- startUpload(); |
|
32 |
- return super.onStartCommand(intent, flags, startId); |
|
25 |
+ startQuery(); |
|
26 |
+ return START_STICKY; |
|
33 | 27 |
} |
34 | 28 |
|
35 |
- private synchronized void startUpload(){ |
|
36 |
- if(currentPhoto!=null){ |
|
37 |
- LogHelper.d("czy","当前有图片正在上传"+currentPhoto); |
|
38 |
- return; |
|
39 |
- } |
|
40 |
- currentPhoto = DBService.getInstance().getNextUploadPhoto(); |
|
41 |
- if(currentPhoto==null){ |
|
42 |
- LogHelper.d("czy","本地图片已全部上传"); |
|
43 |
- return; |
|
44 |
- } |
|
45 |
- LogHelper.d("czy","即将上传的照片是"+currentPhoto); |
|
46 |
- new UploadTask(currentPhoto,this).executeOnExecutor(ThreadExecutor.getInstance().getExecutor()); |
|
47 |
- } |
|
29 |
+ private void startQuery(){ |
|
30 |
+ HashMap<String,String> params = new HashMap<>(); |
|
31 |
+ params.put("user_id", Preferences.getInstance().getLensManId()); |
|
32 |
+ new HttpPostTask(params){ |
|
33 |
+ OrderBean orderBean; |
|
34 |
+ @Override |
|
35 |
+ protected boolean parseResponse(String response) { |
|
36 |
+ orderBean = new OrderBean(); |
|
48 | 37 |
|
49 |
- @Override |
|
50 |
- public void onPhotoUploadSucceed(PhotoBean bean) { |
|
51 |
- if(bean.equals(currentPhoto)){ |
|
52 |
- currentPhoto.uploadStatus = PhotoBean.UploadStatus.STATUS_SUCCESS; |
|
53 |
- DBService.getInstance().updatePhotoBean(currentPhoto); |
|
54 |
- if(listener!=null){ |
|
55 |
- listener.onPhotoUploaded(currentPhoto); |
|
38 |
+ return super.parseResponse(response); |
|
56 | 39 |
} |
57 |
- currentPhoto = null; |
|
58 |
- } |
|
59 |
- startUpload(); |
|
60 |
- } |
|
61 | 40 |
|
62 |
- @Override |
|
63 |
- public void onPhotoUploadFail(PhotoBean bean) { |
|
64 |
- if(bean.equals(currentPhoto)){ |
|
65 |
- currentPhoto.uploadStatus = PhotoBean.UploadStatus.STATUS_ERROR; |
|
66 |
- DBService.getInstance().updatePhotoBean(currentPhoto); |
|
67 |
- if(listener!=null){ |
|
68 |
- listener.onPhotoUploadError(currentPhoto); |
|
41 |
+ @Override |
|
42 |
+ protected void onPostSuccess() { |
|
43 |
+ super.onPostSuccess(); |
|
44 |
+ onNewOrderArrived(orderBean); |
|
69 | 45 |
} |
70 |
- currentPhoto = null; |
|
71 |
- } |
|
72 |
- startUpload(); |
|
73 |
- } |
|
74 | 46 |
|
75 |
- public void setPhotoUploadListener(PhotoUploadListener listener){ |
|
76 |
- this.listener = listener; |
|
47 |
+ @Override |
|
48 |
+ protected void onPostFail() { |
|
49 |
+ super.onPostFail(); |
|
50 |
+ } |
|
51 |
+ }.executeOnExecutor(ThreadExecutor.getInstance().getExecutor()); |
|
52 |
+ |
|
77 | 53 |
} |
78 | 54 |
|
79 |
- public interface PhotoUploadListener{ |
|
80 |
- void onPhotoUploaded(PhotoBean bean); |
|
81 |
- void onPhotoUploadError(PhotoBean bean); |
|
55 |
+ private void onNewOrderArrived(OrderBean bean){ |
|
56 |
+ |
|
82 | 57 |
} |
83 | 58 |
|
84 |
- public class MyBinder extends Binder { |
|
59 |
+ public class OrderServiceBinder extends Binder { |
|
85 | 60 |
|
86 | 61 |
public OrderDealService getService(){ |
87 | 62 |
return OrderDealService.this; |
@@ -37,6 +37,7 @@ public class UrlContainer { |
||
37 | 37 |
|
38 | 38 |
public static final String BRIEFS_URL = HOST_URL+"l/brief"; |
39 | 39 |
|
40 |
+ public static final String QUERY_ORDER_URL = HOST_URL+"l/query"; |
|
40 | 41 |
|
41 | 42 |
|
42 | 43 |
} |